﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
#if NET40
using System.Net;
#else
using System.Net.Http;
#endif

namespace SAM.Framework.CustomHttpClient
{
    /// <summary>
    /// 自定义的httpClient类，实现http和https的模拟请求，且支持cookie的写入
    /// </summary>
    public interface ICustomHttpClient
    {
#if NET40
        /// <summary>
        /// Get同步版本
        /// </summary>
        /// <param name="url">地址</param>
        /// <param name="https">是否为https请求</param>
        /// <param name="cookie">cookie</param>
        /// <param name="header">请求头</param>
        /// <param name="reponseHanlder">回调函数</param>
        string Get(string url, bool https = false, Dictionary<string, string> cookies = null, Dictionary<string, string> headers = null);

        /// <summary>
        /// Post同步请求
        /// </summary>
        /// <param name="url">地址</param>
        /// <param name="postData">请求的数据体</param>
        /// <param name="https">是否为https请求</param>
        /// <param name="cookie">cookie</param>
        /// <param name="header">请求头</param>
        /// <param name="reponseHanlder">回调函数</param>
        string Post(string url, string postData, bool https = false, Dictionary<string, string> cookies = null, Dictionary<string, string> headers = null);
#else
        /// <summary>
        /// Get同步版本
        /// </summary>
        /// <param name="url">地址</param>
        /// <param name="https">是否为https请求</param>
        /// <param name="cookie">cookie</param>
        /// <param name="header">请求头</param>
        /// <param name="reponseHanlder">回调函数</param>
        void Get(string url, Action<HttpResponseMessage> reponseHanlder = null, bool https = false, string[] cookies = null, Dictionary<string, string> headers = null);
        /// <summary>
        /// get异步请求
        /// </summary>
        /// <param name="url">地址</param>
        /// <param name="https">是否为https请求</param>
        /// <param name="cookie">cookie</param>
        /// <param name="header">请求头</param>
        /// <param name="reponseHanlder">回调函数</param>
        Task<HttpResponseMessage> GetAsync(string url, bool https = false, string[] cookies = null, Dictionary<string, string> headers = null);

        /// <summary>
        /// Post同步版本
        /// </summary>
        /// <param name="url">地址</param>
        /// <param name="postData">请求的数据体</param>
        /// <param name="https">是否为https请求</param>
        /// <param name="cookie">cookie</param>
        /// <param name="header">请求头</param>
        /// <param name="reponseHanlder">回调函数</param>
        void Post(string url, string postData, Action<HttpResponseMessage> reponseHanlder = null, bool https = false, string[] cookies = null, Dictionary<string, string> headers = null);

        /// <summary>
        /// Post异步请求
        /// </summary>
        /// <param name="url">地址</param>
        /// <param name="postData">请求的数据体</param>
        /// <param name="https">是否为https请求</param>
        /// <param name="cookie">cookie</param>
        /// <param name="header">请求头</param>
        /// <param name="reponseHanlder">回调函数</param>
        Task<HttpResponseMessage> PostAsync(string url, string postData, bool https = false, string[] cookies = null, Dictionary<string, string> headers = null);
#endif
    }
}
